package com.shangma.controller;

import com.shangma.entity.User;
import com.shangma.utils.AsyncFactory;
import com.shangma.utils.AsyncManager;
import com.shangma.utils.SpringTaskTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("test")
public class TestController {
    @Autowired
    private AsyncManager asyncManager;
    @PostMapping("regist")
    public String regist(@RequestBody User user){
        return "success";
    }

    @PutMapping("update/{phone}/{code}")
    public String update(@PathVariable String phone,@PathVariable String code){
        System.out.println("电话号码是" + phone);
        System.out.println("验证码是" + code);
        // 更新操作
        return "success";
    }

    @DeleteMapping("delete/{keys}")
    public String delete(@PathVariable String keys){
        System.out.println(keys);
        // 如果真的要批量删除，以下代码要放在service层中删除
//        String[] split = keys.split(",");
//        List<String> strings = Arrays.asList(split);
//        strings.forEach(str ->{
//            Long aLong = Long.valueOf(str);
//
//        });

        return "success";
    }

    @GetMapping("sendmail")
    public String sendMail(){
        String email = "gfsios@163.com";
        String message = "今天天气很好，出去玩吧";
        asyncManager.execute(AsyncFactory.sendMail(email,message));
        System.out.println("主线程继续向下执行");
        return "success";
    }
}
